package com.lizongbo.seotijian.rules.whois.domainhandlers;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import com.lizongbo.seotijian.rules.whois.DomainHandler;
import com.lizongbo.seotijian.rules.whois.WhoisClient;
import com.lizongbo.seotijian.util.HttpUtil;

public class AZDomainHandler implements DomainHandler {
	@Override
	public String getTld() {
		return ".az";
	}

	@Override
	public String getWhoisInfo(String domain) {
		String urlStr = "http://www.nic.az/cgi-bin/whois.cgi";
		String query = "lang=en&domain=google&dom=.az";
		String ss[] = new String[] { ".az", ".com.az", ".co.az", ".net.az",
				".int.az", ".gov.az", ".biz.az", ".org.az", ".edu.az",
				".mil.az", ".pp.az", ".name.az", ".info.az", };
		for (int i = 0; i < ss.length; i++) {
			if (domain.endsWith(ss[i])) {
				query = "lang=en&domain="
						+ domain.substring(0, domain.indexOf(ss[i])) + "&dom="
						+ ss[i];
			}
		}
		String txt = "";
		try {
			txt = WhoisClient.trimEmptyLine(WhoisClient.html2txt(HttpUtil.httpPost(urlStr, query,
							"http://www.nic.az/cgi-bin/whois.cgi")));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return txt;
	}
}